home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / newrouts / newrouts.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-06-13  |  16.0 KB  |  498 lines

  1. VERSION 4.00
  2. Begin VB.Form frmNewRouts 
  3.    Caption         =   "Add a new Routine"
  4.    ClientHeight    =   3285
  5.    ClientLeft      =   3540
  6.    ClientTop       =   1905
  7.    ClientWidth     =   4935
  8.    Height          =   3975
  9.    Icon            =   "NewRouts.frx":0000
  10.    Left            =   3480
  11.    LinkTopic       =   "Form1"
  12.    LockControls    =   -1  'True
  13.    ScaleHeight     =   3285
  14.    ScaleWidth      =   4935
  15.    Top             =   1275
  16.    Width           =   5055
  17.    Begin VB.Frame Frame1 
  18.       Height          =   420
  19.       Left            =   30
  20.       TabIndex        =   15
  21.       Top             =   0
  22.       Width           =   4875
  23.       Begin VB.OptionButton optSub 
  24.          Caption         =   "&Sub Procedure"
  25.          Height          =   225
  26.          Left            =   90
  27.          TabIndex        =   17
  28.          Top             =   135
  29.          Value           =   -1  'True
  30.          Width           =   2055
  31.       End
  32.       Begin VB.OptionButton optFunction 
  33.          Caption         =   "F&unction"
  34.          Height          =   195
  35.          Left            =   3135
  36.          TabIndex        =   16
  37.          Top             =   150
  38.          Width           =   1455
  39.       End
  40.    End
  41.    Begin VB.TextBox txtMaxLen 
  42.       BeginProperty Font 
  43.          name            =   "Fixedsys"
  44.          charset         =   0
  45.          weight          =   400
  46.          size            =   9
  47.          underline       =   0   'False
  48.          italic          =   0   'False
  49.          strikethrough   =   0   'False
  50.       EndProperty
  51.       Height          =   330
  52.       Left            =   105
  53.       TabIndex        =   8
  54.       Top             =   2925
  55.       Visible         =   0   'False
  56.       Width           =   495
  57.    End
  58.    Begin VB.TextBox txtSinNum 
  59.       BeginProperty Font 
  60.          name            =   "Fixedsys"
  61.          charset         =   0
  62.          weight          =   400
  63.          size            =   9
  64.          underline       =   0   'False
  65.          italic          =   0   'False
  66.          strikethrough   =   0   'False
  67.       EndProperty
  68.       Height          =   330
  69.       Left            =   3465
  70.       TabIndex        =   4
  71.       Top             =   2430
  72.       Width           =   1305
  73.    End
  74.    Begin VB.TextBox txtProgName 
  75.       BeginProperty Font 
  76.          name            =   "Fixedsys"
  77.          charset         =   0
  78.          weight          =   400
  79.          size            =   9
  80.          underline       =   0   'False
  81.          italic          =   0   'False
  82.          strikethrough   =   0   'False
  83.       EndProperty
  84.       Height          =   330
  85.       Left            =   1110
  86.       TabIndex        =   1
  87.       Top             =   885
  88.       Width           =   3645
  89.    End
  90.    Begin VB.ComboBox cboRetType 
  91.       BeginProperty Font 
  92.          name            =   "Fixedsys"
  93.          charset         =   0
  94.          weight          =   400
  95.          size            =   9
  96.          underline       =   0   'False
  97.          italic          =   0   'False
  98.          strikethrough   =   0   'False
  99.       EndProperty
  100.       Height          =   345
  101.       ItemData        =   "NewRouts.frx":0442
  102.       Left            =   1110
  103.       List            =   "NewRouts.frx":0467
  104.       TabIndex        =   3
  105.       Top             =   2430
  106.       Width           =   1275
  107.    End
  108.    Begin VB.CommandButton cmdAddVariable 
  109.       Caption         =   "Add &Parameters ..."
  110.       Height          =   345
  111.       Left            =   3360
  112.       TabIndex        =   5
  113.       Top             =   2820
  114.       Width           =   1470
  115.    End
  116.    Begin VB.CommandButton cmdAbort 
  117.       Caption         =   "&Abort Build"
  118.       Height          =   345
  119.       Left            =   2280
  120.       TabIndex        =   7
  121.       Top             =   2835
  122.       Width           =   1020
  123.    End
  124.    Begin VB.CommandButton cmdBuild 
  125.       Caption         =   "&Build Routine"
  126.       Height          =   330
  127.       Left            =   1110
  128.       TabIndex        =   6
  129.       Top             =   2850
  130.       Width           =   1125
  131.    End
  132.    Begin VB.TextBox txtDesc 
  133.       BeginProperty Font 
  134.          name            =   "Fixedsys"
  135.          charset         =   0
  136.          weight          =   400
  137.          size            =   9
  138.          underline       =   0   'False
  139.          italic          =   0   'False
  140.          strikethrough   =   0   'False
  141.       EndProperty
  142.       Height          =   1065
  143.       Left            =   1110
  144.       MultiLine       =   -1  'True
  145.       TabIndex        =   2
  146.       Top             =   1305
  147.       Width           =   3645
  148.    End
  149.    Begin VB.TextBox txtAuthor 
  150.       BeginProperty Font 
  151.          name            =   "Fixedsys"
  152.          charset         =   0
  153.          weight          =   400
  154.          size            =   9
  155.          underline       =   0   'False
  156.          italic          =   0   'False
  157.          strikethrough   =   0   'False
  158.       EndProperty
  159.       Height          =   330
  160.       Left            =   1110
  161.       TabIndex        =   0
  162.       Top             =   510
  163.       Width           =   3645
  164.    End
  165.    Begin VB.Label Label6 
  166.       Caption         =   "Sin# (if any) :"
  167.       Height          =   285
  168.       Left            =   2565
  169.       TabIndex        =   14
  170.       Top             =   2445
  171.       Width           =   885
  172.    End
  173.    Begin VB.Label Label5 
  174.       Caption         =   "Function"
  175.       Height          =   225
  176.       Left            =   75
  177.       TabIndex        =   13
  178.       Top             =   2250
  179.       Width           =   855
  180.    End
  181.    Begin VB.Label Label4 
  182.       Caption         =   "Routine Name:"
  183.       Height          =   390
  184.       Left            =   45
  185.       TabIndex        =   12
  186.       Top             =   885
  187.       Width           =   975
  188.    End
  189.    Begin VB.Label Label3 
  190.       Caption         =   "Return Type :"
  191.       Height          =   300
  192.       Left            =   75
  193.       TabIndex        =   11
  194.       Top             =   2445
  195.       Width           =   1065
  196.    End
  197.    Begin VB.Label Label2 
  198.       Caption         =   "Description :"
  199.       Height          =   345
  200.       Left            =   75
  201.       TabIndex        =   10
  202.       Top             =   1305
  203.       Width           =   990
  204.    End
  205.    Begin VB.Label Label1 
  206.       Caption         =   "Author :"
  207.       Height          =   255
  208.       Left            =   60
  209.       TabIndex        =   9
  210.       Top             =   480
  211.       Width           =   1050
  212.    End
  213.    Begin VB.Menu mnFile 
  214.       Caption         =   "&File"
  215.       Begin VB.Menu mnExit 
  216.          Caption         =   "&Exit"
  217.       End
  218.    End
  219.    Begin VB.Menu mnHelp 
  220.       Caption         =   "&Help"
  221.       Begin VB.Menu mnAbout 
  222.          Caption         =   "&About"
  223.       End
  224.    End
  225. Attribute VB_Name = "frmNewRouts"
  226. Attribute VB_Creatable = False
  227. Attribute VB_Exposed = False
  228. Dim retcode&
  229. Private Sub cmdAbort_Click()
  230.     ResetScr
  231.     Unload Me
  232. End Sub
  233. Private Sub cmdAddVariable_Click()
  234.     Dim ub%, i%
  235.     On Error GoTo Loadfrm
  236.     ub% = UBound(gParms())
  237.     On Error GoTo 0
  238.     For i = 0 To ub%
  239.         frmAddVariables.lstVars.AddItem gParms(i)
  240.     Next i
  241. Loadfrm:
  242.     frmAddVariables.Show vbModal
  243. End Sub
  244. Sub BuildRoutine()
  245.     '**************************************
  246.     '* Author : Michael J. Cox
  247.     '* Date : 6/13/97
  248.     '* Email : mikec247@ix.netcom.com
  249.     '*
  250.     '* Desc:
  251.     '*   This routine does all the work.
  252.     '*   It builds a temporary ascii file and
  253.     '*   then load it into the active form.
  254.     '*
  255.     '*   Modify this routine to customize the
  256.     '*   new routine template.
  257.     '***********************************
  258.     On Error GoTo BuildRoutineErr
  259.     Dim CurForm As Object, maxlen%
  260.     Dim i%, nFileHnd%, dSub$, dDate$, oldtext$
  261.     Dim dArgs$, dParmsDesc$(), dParms$()
  262.     Dim dTab$, tParms%, dRetType$
  263.     dDate = Date
  264.     dTab$ = Space(4)
  265.     maxlen% = gMaxLen%
  266.     Set CurForm = gobjVBInst.ActiveProject.ActiveForm
  267.     On Error GoTo noParms
  268.     tParms% = UBound(gParms()) + 1
  269. noParms:
  270.     On Error GoTo BuildRoutineErr
  271.     nFileHnd = FreeFile
  272.     Open App.Path & "\Routine.txt" For Output As nFileHnd
  273.     If gIsFunction And (cboRetType.Text) <> "" Then
  274.         dSub$ = "Function "
  275.         dRetType$ = " As " & Trim(cboRetType.Text)
  276.     Else
  277.         dSub$ = "Sub "
  278.         dRetType$ = ""
  279.     End If
  280.            
  281.     Print #nFileHnd, "Private " & dSub$ & Trim(txtProgName) & "(" & getArgs(tParms%) & ")" & dRetType$
  282.     Print #nFileHnd, dTab & "'" & String(maxlen%, "*")
  283.     Print #nFileHnd, dTab & "'* Routine Name : " & Trim(txtProgName)
  284.     Print #nFileHnd, dTab & "'* Author Name : " & Trim(txtAuthor)
  285.     Print #nFileHnd, dTab & "'* Date : " & dDate$
  286.     If Trim(txtSinNum.Text) <> "" Then
  287.         Print #nFileHnd, dTab & "'*"
  288.         Print #nFileHnd, dTab & "'* Sin Number : " & Trim(txtSinNum.Text)
  289.     End If
  290.     Print #nFileHnd, dTab & "'*"
  291.     Print #nFileHnd, dTab & "'* Description :"
  292.     If Trim(txtDesc) = "" Then
  293.         Print #nFileHnd, dTab & "'*     (Enter Description) "
  294.     Else
  295.         oldtext$ = Trim(txtDesc)
  296.         Do While Len(oldtext$)
  297.           Print #nFileHnd, dTab & "'*   " & Descln(oldtext$, maxlen - 4)
  298.         Loop
  299.     End If
  300.     Print #nFileHnd, dTab & "'*"
  301.     Print #nFileHnd, dTab & "'* Parameters :"
  302.     If tParms > 0 Then
  303.         For i = 0 To tParms - 1
  304.           Print #nFileHnd, dTab & "'*   " & gParms(i)
  305.         Next i
  306.     Else
  307.        Print #nFileHnd, dTab & "'*     (Enter Parameters) "
  308.     End If
  309.     Print #nFileHnd, dTab & "'*"
  310.     Print #nFileHnd, dTab & "'* Revision History"
  311.     Print #nFileHnd, dTab & "'* Date    Sin #       Author Id     Description     "
  312.     Print #nFileHnd, dTab & "'* ----    ------      ---------     ----------------"
  313.     Print #nFileHnd, dTab & "'*"
  314.     Print #nFileHnd, dTab & "'" & String(maxlen%, "*")
  315.     Print #nFileHnd, "On Error Goto " & Trim(txtProgName) & "Err"
  316.     Print #nFileHnd, ""
  317.     Print #nFileHnd, ""
  318.     Print #nFileHnd, dTab & "Exit " & dSub$
  319.     Print #nFileHnd, Trim(txtProgName) & "Err:"
  320.     Print #nFileHnd, dTab & "Errorroutine$ = " & Chr(34) & Trim(txtProgName) & Chr(34)
  321.     Print #nFileHnd, dTab & "ErrHandler Err, Errorroutine$"
  322.     Print #nFileHnd, dTab & "Exit " & dSub$
  323.     Print #nFileHnd, "End " & dSub$
  324.     Close nFileHnd
  325.     CurForm.InsertFile App.Path & "\Routine.txt"
  326.     Kill App.Path & "\Routine.txt" 'delete the code file
  327.     Set CurForm = Nothing
  328.     Exit Sub
  329. BuildRoutineErr:
  330.     retcode = MsgBox("Error in BuildRoutine" & _
  331.             vbCrLf & Err.Description _
  332.         , vbCritical + vbOKOnly, "NewRouts 1.0")
  333. End Sub
  334. Function getArgs$(ub%)
  335.     '**************************************
  336.     '* Author : Michael J. Cox
  337.     '* Date : 6/13/97
  338.     '* Email : mikec247@ix.netcom.com
  339.     '*
  340.     '* Desc:
  341.     '*   This routine builds the parameters
  342.     '*   from the global array gParms().
  343.     '***********************************
  344.     Dim i%, ret$
  345.     If ub% = 0 Then
  346.         Exit Function
  347.     End If
  348.     For i = 0 To ub - 1
  349.       ret$ = ret$ & Trim(Mid(gParms(i), 1, 20)) & ", "
  350.     Next i
  351.     getArgs$ = Left(ret$, Len(ret$) - 2)
  352. End Function
  353. Private Sub cmdBuild_Click()
  354.     'Check for Sub name
  355.     If Trim(frmNewRouts.txtProgName) = "" Then
  356.         Beep
  357.         Exit Sub
  358.     End If
  359.     'Insert comments and error trap
  360.     BuildRoutine
  361.     'Check and save if different the Author's id
  362.     If UCase(Trim(txtAuthor.Text)) <> UCase(Trim(gAuthorName)) And Trim(txtAuthor.Text) <> "" Then
  363.         gAuthorName$ = Trim(txtAuthor.Text)
  364.         SaveSetting "NewRout", "UserConf", "AuthorName", gAuthorName$
  365.     End If
  366.     'Check and save if different the Author's id
  367.     If Val(UCase(Trim(txtMaxLen.Text))) <> gMaxLen% And Val(Trim(txtMaxLen.Text)) <> 0 Then
  368.         gMaxLen = Val(Trim(txtMaxLen.Text))
  369.         SaveSetting "NewRout", "UserConf", "MaxLen", Str$(gMaxLen%)
  370.     End If
  371.     'Clear Screen
  372.     ResetScr
  373.     'Unload Form
  374.     Unload Me
  375. End Sub
  376. Sub ResetScr()
  377.     '**************************************
  378.     '* Author : Michael J. Cox
  379.     '* Date : 6/13/97
  380.     '* Email : mikec247@ix.netcom.com
  381.     '*
  382.     '* Desc:
  383.     '*   This routine clears the input
  384.     '*   fields on the form.
  385.     '***********************************
  386.     txtDesc.Text = ""
  387.     txtProgName.Text = ""
  388.     txtSinNum.Text = ""
  389.     cboRetType.Text = ""
  390.     Erase gParms()
  391. End Sub
  392. Private Sub Form_Activate()
  393.     SetFocus
  394. End Sub
  395. Private Sub Form_Load()
  396.     '**************************************
  397.     '* Author : Michael J. Cox
  398.     '* Date : 6/13/97
  399.     '* Email : mikec247@ix.netcom.com
  400.     '*
  401.     '* Desc:
  402.     '*   This form allows the user to enter
  403.     '*   the Author name, Program Name, and
  404.     '*   other information need to build the
  405.     '*   Routine's shell.
  406.     '***********************************
  407.     'center it on the screen
  408.     Me.Top = (Screen.Height - Me.Height) \ 2
  409.     Me.Left = (Screen.Width - Me.Width) \ 2
  410. End Sub
  411. Private Sub mnAbout_Click()
  412.     retcode = MsgBox("Add an OPICS Routine Addin" & _
  413.             vbCrLf & "        created by         " & _
  414.             vbCrLf & "      Michael J. Cox" & _
  415.             vbCrLf & "Email: mikec247@ix.netcom.com" _
  416.         , vbInformation + vbOKOnly, "NewRouts 1.0")
  417. End Sub
  418. Private Sub mnExit_Click()
  419.     ResetScr
  420.     Unload Me
  421. End Sub
  422. Private Sub optFunction_Click()
  423.     gIsFunction = True
  424.     frmNewRouts.optFunction = True
  425.     frmNewRouts.Caption = "Add a Function"
  426.     frmNewRouts.cboRetType.Enabled = gIsFunction
  427.     frmNewRouts.cboRetType.Text = ""
  428. End Sub
  429. Private Sub optSub_Click()
  430.     gIsFunction = False
  431.     frmNewRouts.optSub = True
  432.     frmNewRouts.Caption = "Add a Sub Procedure"
  433.     frmNewRouts.cboRetType.Enabled = gIsFunction
  434.     frmNewRouts.cboRetType.Text = ""
  435. End Sub
  436. Function Descln$(oldtext$, maxln%)
  437.     '**************************************
  438.     '* Author : Michael J. Cox
  439.     '* Date : 6/13/97
  440.     '* Email : mikec247@ix.netcom.com
  441.     '*
  442.     '* Desc:
  443.     '*   This routine extracts a line of
  444.     '*   data from the description text box.
  445.     '*   Data is returned based on the maxlen.
  446.     '***********************************
  447.     Dim firstspace%, ret$
  448.     If Len(oldtext) < 1 Then Exit Function
  449.     firstspace% = InStr(1, oldtext$, " ")
  450.     If firstspace% > maxln% Then
  451.         ret$ = Mid(oldtext, 1, maxln% - 1) & "-"
  452.         oldtext$ = Mid(oldtext, maxln%, Len(oldtext) - (maxln% - 1))
  453.     Else
  454.         ret$ = Mid(oldtext, 1, firstspace%)
  455.         oldtext$ = Mid(oldtext, firstspace% + 1, Len(oldtext) - firstspace%)
  456.         firstspace% = InStr(1, oldtext$, " ")
  457.         Do While Len(ret$) + firstspace% <= maxln% And Len(oldtext)
  458.           If firstspace Then
  459.             ret$ = ret$ & Mid(oldtext, 1, firstspace%)
  460.             If firstspace < Len(oldtext) Then
  461.                 oldtext$ = Mid(oldtext, firstspace% + 1, Len(oldtext) - firstspace%)
  462.             Else
  463.                 oldtext$ = ""
  464.             End If
  465.             firstspace% = InStr(1, oldtext$, " ")
  466.           Else
  467.             ret$ = ret$ & oldtext
  468.             oldtext$ = ""
  469.           End If
  470.         Loop
  471.     End If
  472.     Descln = ret$
  473. End Function
  474. Private Sub txtAuthor_KeyDown(KeyCode As Integer, Shift As Integer)
  475.     '**************************************
  476.     '* Author : Michael J. Cox
  477.     '* Date : 6/13/97
  478.     '* Email : mikec247@ix.netcom.com
  479.     '*
  480.     '* Desc:
  481.     '*   This routine is an Easter Egg
  482.     '*   routine. '"SHIFT+CTRL+ALT+F2."
  483.     '***********************************
  484.     Dim ShiftDown, AltDown, CtrlDown, Txt
  485.     Const vbKeyF2 = &H71    ' Define constants.
  486.     Const vbShiftMask = 1
  487.     Const vbCtrlMask = 2
  488.     Const vbAltMask = 4
  489.     ShiftDown = (Shift And vbShiftMask) > 0
  490.     AltDown = (Shift And vbAltMask) > 0
  491.     CtrlDown = (Shift And vbCtrlMask) > 0
  492.     If KeyCode = vbKeyF2 Then   ' Display key combinations.
  493.         If ShiftDown And CtrlDown And AltDown Then
  494.             EasterEgg = True
  495.         End If
  496.     End If
  497. End Sub
  498.